/* $Id: ProcessStepActionDAOImpl.java 
 * Copyright (C) 2011, TRAKHEES
 *  
 * Revision History
 *
 * Date  			Author 		    	Remarks
 * ---------------------------------------------------------------------------------
 *
 */
package ae.pcfc.etks.online.common.dao.provider;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import ae.pcfc.etks.online.common.ConstantsCommon;
import ae.pcfc.etks.online.common.dao.ProcessStepActionDAO;
import ae.pcfc.etks.online.common.domain.ProcStepActions;
import ae.pcfc.etks.online.common.domain.ProcessStep;

public class ProcessStepActionDAOImpl extends BaseDAO implements
		ProcessStepActionDAO {

	/**
	 * add
	 * 
	 * @see ae.pcfc.etks.online.common.dao.ProcessStepActionDAO#add(ae.pcfc.etks.online.common.domain.ProcStepActions)
	 * 
	 */
	public void add(ProcStepActions procStepActions) {
		// TODO Auto-generated method stub

	}

	/**
	 * isApplicationApprovedByDepartment
	 * 
	 * @see ae.pcfc.etks.online.common.dao.ProcessStepActionDAO#isApplicationApprovedByDepartment(java.lang.String, java.lang.String)
	 * 
	 */
	public boolean isApplicationApprovedByDepartment(String code,
			String applicationId) {
		Criteria criteria = getHibernateTemplate().getSessionFactory()
				.getCurrentSession()
				.createCriteria(ProcStepActions.class, "procStepAction");
		criteria.createAlias("procStepAction.appMetaData", "appMetaData");
		criteria.createAlias("procStepAction.processStep", "processStep");
		criteria.add(Restrictions
				.eq("appMetaData.applicationId", applicationId));
		criteria.add(Restrictions.like("processStep.processStepCode", "%"
				+ code + "%").ignoreCase());
		criteria.add(Restrictions.eq("procStepAction.actionDesc",
				ConstantsCommon.APPROVE));
		@SuppressWarnings("unchecked")
		List<ProcessStep> list = criteria.list();
		if (list != null && list.size() > 0)
			return true;
		else
			return false;

	}

	/**
	 * isApplicationActedByDepartment
	 * 
	 * @see ae.pcfc.etks.online.common.dao.ProcessStepActionDAO#isApplicationActedByDepartment(java.lang.String, java.lang.String)
	 * 
	 */
	public boolean isApplicationActedByDepartment(String code,
			String applicationId) {
		Criteria criteria = getHibernateTemplate().getSessionFactory()
				.getCurrentSession()
				.createCriteria(ProcStepActions.class, "procStepAction");
		criteria.createAlias("procStepAction.appMetaData", "appMetaData");
		criteria.createAlias("procStepAction.processStep", "processStep");
		criteria.add(Restrictions
				.eq("appMetaData.applicationId", applicationId));
		criteria.add(Restrictions.like("processStep.processStepCode", "%"
				+ code));
		@SuppressWarnings("unchecked")
		List<ProcessStep> list = criteria.list();
		if (list != null && list.size() > 0)
			return true;
		else
			return false;
	}

}
